// sd_liferuning/pages/constmer/balance-recharge/index.js
var api = require("../../../../api.js"),app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    money: 0
  },    
  changeInputData: function (e) {
    var that = this;
    var inputName = e.currentTarget.dataset.name;
    var inputVlaue = e.detail.value;
    if (inputName == "money") {
      that.setData({
        money: inputVlaue
      });
    }
  },
  onLoad:function(){
    var that = this
    that.setData({
      icons: wx.getStorageSync('site') + '/addons/sd_liferuning/tp/public/uploads/background',
    })
  },
  sendRequest: function(){
    
    var that=this;
    if (!that.data.money){
      wx.showToast({
        title: '请输入金额',
        icon:'none'
      })
      return false;
    }
    var money = that.data.money;
    app.request({
      url: api.order.rechargePay,
   
      data:{
        uid:wx.getStorageSync('uid'),
        bid:wx.getStorageSync('bid'),
        money: money
      },
      
      success:function(e){
        var pay = e.data.weixin;
      
       wx.requestPayment({
         timeStamp: pay.timeStamp,
         nonceStr: pay.nonceStr,
         package: pay.package,
         signType: pay.signType,
         paySign: pay.paySign,
        success:function(res){
          wx.showToast({
            title: '充值成功',
            duration:1000,
            success:function(){
              setTimeout(function () {
                wx.navigateBack({
                  delta: 1
                })
              }, 1000)
            }
          })
        }
       },
     
       )
      }
      
    })
  
  }
})